package com.ctg.payroll2.service.social.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.ctg.payroll2.bean.filter.social.PbSocialTypeFilter;
import com.ctg.payroll2.bean.po.social.PbSocialType;
import com.ctg.payroll2.service.BaseService;
import com.ctg.payroll2.service.social.PbSocialTypeService;
import com.ctg.platform.orm.ibatis.IbatisEntityDao;
import com.ctg.platform.util.Page;
/**
 * 社保类型service实现
 * @author 鲁力 2009-9-7 下午06:39:26
 *
 */
@SuppressWarnings("unchecked")
public class PbSocialTypeServiceImpl extends BaseService implements PbSocialTypeService {
	private IbatisEntityDao ibatisEntityDao;
	
	public void insertPbSocialType(PbSocialType pbSocialType) {
		getDao().getSqlMapClientTemplate().insert(getNameSpace()+".addPbSocialType", pbSocialType);
	}

	public void deletePbSocialTypeByIds(String delIds, String updIds) {
		if (StringUtils.isNotEmpty(delIds)) {
			getDao().getSqlMapClientTemplate().delete(getNameSpace()+".deletePbSocialTypeByIds", delIds);
		}
		if (StringUtils.isNotEmpty(updIds)) {
			getDao().getSqlMapClientTemplate().delete(getNameSpace()+".setPbSocialTypeInvalidateByIds", updIds);
		}
	}

	public PbSocialType getPbSocialTypeById(Long id) {
		if (id==null) {
			return null;
		}
		Map<String, Long> map =  new HashMap<String, Long>();
		map.put("typeId", id);
		List<PbSocialType> list = getDao().getSqlMapClientTemplate().queryForList(getNameSpace()+".getPbSocialTypeByIdOrName", map);
		if (list.size()==1) {
			return list.get(0);
		}else
			return null;
	}
	
	public PbSocialType getPbSocialTypeByName(String name) {
		if (StringUtils.isEmpty(name)) {
			return null;
		}
		Map<String, String> map =  new HashMap<String, String>();
		map.put("typeName", name);
		List<PbSocialType> list = getDao().getSqlMapClientTemplate().queryForList(getNameSpace()+".getPbSocialTypeByIdOrName", map);
		if (list.size()==1) {
			return list.get(0);
		}else
			return null;
	}

	public Page getPbSocialTypePageByFilter(PbSocialTypeFilter filter) {
		return ibatisEntityDao.pagedQueryByFilter(this.getClass(), filter, 
				".getPbSocialTypeByFilter_count",
				".getPbSocialTypeByFilter_query");
	}

	public List<PbSocialType> getPbSocialTypeListByFilter(PbSocialTypeFilter filter) {
		return ibatisEntityDao.getSqlMapClientTemplate().queryForList(getNameSpace()+".getPbSocialTypeByFilter", filter);
	}

	public void updatePbSocialType(PbSocialType pbSocialType) {
		getDao().getSqlMapClientTemplate().update(getNameSpace()+".updatePbSocialType", pbSocialType);
	}
	/************************************************************************
	 * getter, setter method
	 ***********************************************************************/
	
	/**
	 * @param ibatisEntityDao 设置ibatisEntityDao
	 */
	public void setIbatisEntityDao(IbatisEntityDao ibatisEntityDao) {
		this.ibatisEntityDao = ibatisEntityDao;
	}

	/**
	 * @return 返回ibatisEntityDao
	 */
	public IbatisEntityDao getDao() {
		return ibatisEntityDao;
	}

}
